package com.itheima.chapter03.controller;

import com.itheima.chapter03.domain.AjaxResult;
import com.itheima.chapter03.entity.Discuss;
import com.itheima.chapter03.service.DiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/discuss")
public class DiscussController {
    @Autowired
    private DiscussService discussService;

    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Integer id) {
        Discuss discuss = discussService.findById(id);
        if (discuss == null) {
            return AjaxResult.error("没有找到制定记录");
        }
        return AjaxResult.success(discuss);
    }

    @GetMapping
    public AjaxResult list(@RequestParam int aId,
                           @RequestParam(required = false, defaultValue = "1") int pageNo,
                           @RequestParam(required = false, defaultValue = "3") int pageSize) {
        return AjaxResult.success(discussService.list(aId, pageNo - 1, pageSize));
    }
}
